<template>
  <!-- 修改主页文字 -->
  <div class="add_news">
    <el-title :title="title"></el-title>
    <div class="news">
      <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
        <el-form-item label="站点名称" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="版权信息" prop="zhuban">
          <el-input v-model="ruleForm.zhuban"></el-input>
        </el-form-item>
        <el-form-item label="工信部备案" prop="beian1">
          <el-input v-model="ruleForm.beian" placeholder="请输入工信部备案" style="width: calc(50% - 10px); margin-right: 20px;"></el-input>
          <el-input v-model="ruleForm.beiana" placeholder="请输入工信部备案链接" style="width: calc(50% - 10px);"></el-input>
        </el-form-item>
        <el-form-item label="公安备案" prop="beian2">
          <el-input v-model="ruleForm.beian2" placeholder="请输入公安备案" style="width: calc(50% - 10px); margin-right: 20px;"></el-input>
          <el-input v-model="ruleForm.beian2a" placeholder="请输入公安备案链接" style="width: calc(50% - 10px);"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import elTitle from '@/components/title.vue'
import { getName, amendName } from '@/utils/index.js'
export default {
  data() {
    return {
      title: '站点信息',
      ruleForm: {
        // 站点名称
        name: '',
        // 主办信息
        zhuban: '',
        // 备案信息1
        beian: '',
        beiana: '',
        // 备案信息2
        beian2: '',
        beian2a: '',
      },
    }
  },
  computed: {},
  components: {
    elTitle,
  },
  created() {
    // 查询到旧的名字
    getName().then((res) => {
      console.log(res.data)
      this.ruleForm.name = res.data.name
      this.ruleForm.zhuban = res.data.zhuban
      this.ruleForm.beian = res.data.beian
      this.ruleForm.beiana = res.data.beiana
      this.ruleForm.beian2 = res.data.beian2
      this.ruleForm.beian2a = res.data.beian2a
    })
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(() => {
        amendName({
          name: this.ruleForm.name,
          zhuban: this.ruleForm.zhuban,
          beian: this.ruleForm.beian,
          beiana: this.ruleForm.beiana,
          beian2: this.ruleForm.beian2,
          beian2a: this.ruleForm.beian2a,
        }).then((res) => {
          if (res.code == '0') {
            // 更改成功
            this.$message.success(res.msg)
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.news {
  background-color: white;
  margin-top: 15px;
  padding: 50px;
}
</style>